"use strict";
cc._RF.push(module, '90981TSvDdLw6cm2v35vm8F', 'FreeCarView');
// scripts/FreeCarView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("CarConstant"),
    s = t("GlobalUserData"),
    l = t("GameConstant"),
    c = t("CarRoleView"),
    d = t("BroadCastMessage"),
    h = t("Util"),
    p = t("Particle"),
    u = t("Global"),
    f = t("BaseStorage"),
    m = t("AssemblyItem"),
    _ = t("ConfirmRewardPanel"),
    y = t("HallCarTotalView"),
    g = t("HallConstant"),
    v = t("HallScene"),
    C = cc._decorator,
    b = C.ccclass,
    w = C.property,
    S = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.node_content = null, e.pfb_assembly = null, e.pfb_role = null, e.label_Power = null, e.arr_prize = [], e.pro = null, e.node_arrow = null, e.iconPrefab = null, e.node_proNode = null, e.frame_coin = null, e.frame_diamond = null, e.label_pro = null, e.roleControl = null, e.equipBodyData = null, e.equipWheelData = [], e.equipWeaponData = [], e.equipToolsData = [], e.equipCarBody = null, e.equipCarWheel = [null, null], e.equipCarWeapon = [null, null], e.equipCarTools = [null, null], e.equipWheelRadius = 0, e;
  }

  return n(e, t), e.prototype.onEnable = function () {
    h.Util.is_OPPO && h.Util.hideHallBanner();
  }, e.prototype.start = function () {
    var t = this;
    h.Util.initCustomCar([{
      bodyId: "body05",
      wheel0Id: "wheel01",
      wheel1Id: "wheel01",
      weapon0Id: r.Weapon_ID.DoubleSaw,
      tool0Id: r.Tools_ID.Harpoon
    }], s["default"].freeCarData, 1, 4), this.scheduleOnce(function () {
      t.createRole(), t.createCarBody(), t.createCarWheel(), t.createCarWeapon(), t.createCarTools(), t.refreshCarPower();
    }, .2), s["default"].videoTab = 26, h.Util.videoExposure(s["default"].videoTab), this.refreshPro();
  }, e.prototype.refreshPro = function () {
    var t = f.BaseStorage.getInt(u.BaseStorageKey.FreeCarPro, 0);
    this.node_arrow.active = t > 0, this.pro.progress = t / 5, this.node_arrow.active && (this.node_arrow.x = this.arr_prize[t - 1].x), this.label_pro.string = "(" + t + "/5)";
  }, e.prototype.createRole = function () {
    var t = s["default"].freeCarData.arrBody[0].id;

    if (t) {
      if (!this.roleControl) {
        var e = cc.instantiate(this.pfb_role);
        this.node_content.addChild(e), this.roleControl = e.getComponent(c["default"]);
      }

      this.roleControl.init(this, l.Physics_Car_Tag.Left, t), this.roleControl.playAniIn();
    }
  }, e.prototype.createCarBody = function () {
    var t = s["default"].freeCarData.arrBody[0];

    if (this.equipBodyData = t, !this.equipCarBody) {
      var e = cc.instantiate(this.pfb_assembly);
      this.node_content.addChild(e), this.equipCarBody = e.getComponent(m.AssemblyItem);
    }

    this.equipCarBody.updateItem(null, !0, 0, t, !1, m.Assembly_Type.SuperCar, !0, !0);
  }, e.prototype.createCarWheel = function () {
    for (var t = 0; t < s["default"].freeCarData.arrWheel.length; t++) {
      var e = s["default"].freeCarData.arrWheel[t];

      if (e) {
        this.equipWheelData[t] = e, this.equipWheelRadius = this.equipWheelRadius < e.radius && e.radius;
        var o = cc.instantiate(this.pfb_assembly);
        this.node_content.addChild(o, 20), o.position = r.GetCarBodyData(s["default"].freeCarData.arrBody[0].id).wheelPos[t], this.equipCarWheel[t] = o.getComponent(m.AssemblyItem), this.equipCarWheel[t].updateItem(null, !0, 0, e, !1, m.Assembly_Type.SuperCar);
      } else this.equipWheelData[t] = null, this.equipCarWheel[t] = null;
    }
  }, e.prototype.createCarWeapon = function () {
    for (var t = 0; t < s["default"].freeCarData.arrWeapon.length; t++) {
      var e = s["default"].freeCarData.arrWeapon[t];

      if (e) {
        this.equipWeaponData[t] = e;
        var o = cc.instantiate(this.pfb_assembly);
        this.node_content.addChild(o, 30), o.position = r.GetCarBodyData(s["default"].freeCarData.arrBody[0].id).weaponPos[t], this.equipCarWeapon[t] = o.getComponent(m.AssemblyItem), this.equipCarWeapon[t].updateItem(null, !0, 0, e, !1, m.Assembly_Type.SuperCar);
      } else this.equipWeaponData[t] = null, this.equipCarWeapon[t] = null;
    }
  }, e.prototype.createCarTools = function () {
    for (var t = 0; t < s["default"].freeCarData.arrTools.length; t++) {
      var e = s["default"].freeCarData.arrTools[t];

      if (e) {
        this.equipToolsData[t] = e;
        var o = cc.instantiate(this.pfb_assembly);
        this.node_content.addChild(o, 40), o.position = r.GetCarBodyData(s["default"].freeCarData.arrBody[0].id).toolsPos[t], this.equipCarTools[t] = o.getComponent(m.AssemblyItem), this.equipCarTools[t].updateItem(null, !0, 0, e, !1, m.Assembly_Type.SuperCar);
      } else this.equipToolsData[t] = null, this.equipCarTools[t] = null;
    }
  }, e.prototype.refreshCarPower = function () {
    var t = 0;
    t += h.Util.getOwnItemPower(this.equipBodyData);

    for (var e = 0; e < this.equipWheelData.length; e++) {
      var o = this.equipWheelData[e];
      t += h.Util.getOwnItemPower(o);
    }

    for (e = 0; e < this.equipWeaponData.length; e++) {
      o = this.equipWeaponData[e], t += h.Util.getOwnItemPower(o);
    }

    for (e = 0; e < this.equipToolsData.length; e++) {
      o = this.equipToolsData[e], t += h.Util.getOwnItemPower(o);
    }

    this.label_Power.string = "战力：" + t.toString(), s["default"].freeCarData.power = this.label_Power.string;
  }, e.prototype.onBtnGetAward = function () {
    var t = this;
    h.Util.showRewardVideo(function () {
      var e = f.BaseStorage.getInt(u.BaseStorageKey.FreeCarPro, 0);
      f.BaseStorage.setInt(u.BaseStorageKey.FreeCarPro, e + 1), t.getAward(f.BaseStorage.getInt(u.BaseStorageKey.FreeCarPro, 0)), t.refreshPro();
    }, null, null, !1);
  }, e.prototype.getAward = function (t) {
    switch (t) {
      case 1:
        this.getGold(6e3);
        break;

      case 2:
        this.getDiamond(150);
        break;

      case 3:
        this.getGold(1e4);
        break;

      case 4:
        this.getDiamond(200);
        break;

      case 5:
        this.onClose(), cc.find("Canvas").getChildByName("car").getComponent(y["default"]).setFreeCar(), cc.find("Canvas").getComponent(v["default"]).refreshNewCommer();
    }
  }, e.prototype.getGold = function (t) {
    var e = this;
    h.Util.showConfirmPanel([{
      type: _.rewardType.gold,
      num: t
    }], function () {
      s["default"].saveGoldData(!0, t), cc.find("Canvas").getComponent(v["default"]).onSetOwnGold(!0), e.action(e.iconPrefab, "frame_gold", e.frame_coin);
    }, !0, function () {
      s["default"].saveGoldData(!0, 2 * t), cc.find("Canvas").getComponent(v["default"]).onSetOwnGold(!0), e.action(e.iconPrefab, "frame_gold", e.frame_coin);
    });
  }, e.prototype.getDiamond = function (t) {
    var e = this;
    h.Util.showConfirmPanel([{
      type: _.rewardType.diamond,
      num: t
    }], function () {
      s["default"].saveDiamondData(!0, t), cc.find("Canvas").getComponent(v["default"]).onSetOwnDiamond(!0), e.action(e.iconPrefab, "frame_diamond", e.frame_diamond);
    }, !0, function () {
      s["default"].saveDiamondData(!0, 2 * t), cc.find("Canvas").getComponent(v["default"]).onSetOwnDiamond(!0), e.action(e.iconPrefab, "frame_diamond", e.frame_diamond);
    });
  }, e.prototype.action = function (t, e, o) {
    d["default"].getInstance().SendMessage(g.Broadcast_Func.Audio, g.Audio_ID.get_gold);

    for (var i = 0; i < 20; i++) {
      var n = cc.instantiate(t),
          a = cc.find("Canvas").getChildByName(e).convertToWorldSpaceAR(cc.Vec2.ZERO),
          r = f.BaseStorage.getInt(u.BaseStorageKey.FreeCarPro, 0) - 1,
          s = this.node_proNode.convertToNodeSpaceAR(a),
          l = this.arr_prize[r].getPosition();
      n.setPosition(l), n.parent = this.node_proNode, n.getComponent(p["default"]).init(h.Util.getRandomInt(0, 360), h.Util.getRandomInt(200, 400), s, o);
    }
  }, e.prototype.onClose = function () {
    h.Util.is_VIVO() && !s["default"].bAuditMode && h.Util.showNativeGridAd(), this.node.destroy(), h.Util.hideNativeBanner(), h.Util.is_qg() && !s["default"].isIllustratedBookView && h.Util.showHallBanner();
  }, a([w(cc.Node)], e.prototype, "node_content", void 0), a([w(cc.Prefab)], e.prototype, "pfb_assembly", void 0), a([w(cc.Prefab)], e.prototype, "pfb_role", void 0), a([w(cc.Label)], e.prototype, "label_Power", void 0), a([w([cc.Node])], e.prototype, "arr_prize", void 0), a([w(cc.ProgressBar)], e.prototype, "pro", void 0), a([w(cc.Node)], e.prototype, "node_arrow", void 0), a([w(cc.Prefab)], e.prototype, "iconPrefab", void 0), a([w(cc.Node)], e.prototype, "node_proNode", void 0), a([w(cc.SpriteFrame)], e.prototype, "frame_coin", void 0), a([w(cc.SpriteFrame)], e.prototype, "frame_diamond", void 0), a([w(cc.Label)], e.prototype, "label_pro", void 0), a([b], e);
}(cc.Component);

o["default"] = S;

cc._RF.pop();